package com.itheima.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pojo.db.PmsProductAttributeCategory;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author Hakuna Matata
 * @date 2022-10-11-21:42
 */
@Data
public class PageResult<T> implements Serializable {
    private Integer pageNum;
    private Integer pageSize;
    private Integer total;
    private Integer totalPage;
    private List<T> list;

    public PageResult() {
    }

    public PageResult(Integer pageNum, Integer pageSize, Integer total, Integer totalPage, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;//总数量
        this.totalPage = totalPage;//总页数
        this.list = list;
    }

    public PageResult(Integer pageNum, Integer pageSize, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.list = list;
    }

    public static  <T>PageResult<T> init(IPage<T> pageInfo){
        return new PageResult<T>((int) pageInfo.getCurrent(), (int) pageInfo.getSize(), (int) pageInfo.getPages(), (int)pageInfo.getTotal(), pageInfo.getRecords());
    }
}
